home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Common / selectDevice.frm < prev   
Text File  |  2001-10-08  |  10KB  |  359 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSelectDevice 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Select Device"
  5.    ClientHeight    =   2805
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5865
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2805
  13.    ScaleWidth      =   5865
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.Frame optRenderingModeoptRenderingMode 
  17.       Caption         =   "Rendering Mode"
  18.       Height          =   1335
  19.       Left            =   120
  20.       TabIndex        =   7
  21.       Top             =   1320
  22.       Width           =   4575
  23.       Begin VB.ComboBox cboFullScreenMode 
  24.          Enabled         =   0   'False
  25.          Height          =   315
  26.          Left            =   2040
  27.          Style           =   2  'Dropdown List
  28.          TabIndex        =   10
  29.          Top             =   720
  30.          Width           =   2295
  31.       End
  32.       Begin VB.OptionButton optRenderingMode 
  33.          Caption         =   "&Fullscreen mode"
  34.          Height          =   375
  35.          Index           =   1
  36.          Left            =   240
  37.          TabIndex        =   9
  38.          Top             =   690
  39.          Width           =   1455
  40.       End
  41.       Begin VB.OptionButton optRenderingMode 
  42.          Caption         =   "Use desktop &window"
  43.          Height          =   375
  44.          Index           =   0
  45.          Left            =   240
  46.          TabIndex        =   8
  47.          Top             =   240
  48.          Value           =   -1  'True
  49.          Width           =   1815
  50.       End
  51.    End
  52.    Begin VB.CommandButton cmdCancel 
  53.       Caption         =   "Cancel"
  54.       Height          =   375
  55.       Left            =   4800
  56.       TabIndex        =   4
  57.       Top             =   720
  58.       Width           =   975
  59.    End
  60.    Begin VB.CommandButton cmdOk 
  61.       Caption         =   "OK"
  62.       Default         =   -1  'True
  63.       Height          =   375
  64.       Left            =   4800
  65.       TabIndex        =   3
  66.       Top             =   240
  67.       Width           =   975
  68.    End
  69.    Begin VB.Frame Frame1 
  70.       Caption         =   "Rendering device"
  71.       Height          =   1095
  72.       Left            =   120
  73.       TabIndex        =   0
  74.       Top             =   120
  75.       Width           =   4575
  76.       Begin VB.ComboBox cboDevice 
  77.          Height          =   315
  78.          Left            =   1440
  79.          Style           =   2  'Dropdown List
  80.          TabIndex        =   6
  81.          Top             =   600
  82.          Width           =   2775
  83.       End
  84.       Begin VB.ComboBox cboAdapter 
  85.          Height          =   315
  86.          Left            =   1440
  87.          Style           =   2  'Dropdown List
  88.          TabIndex        =   2
  89.          Top             =   240
  90.          Width           =   2775
  91.       End
  92.       Begin VB.Label Label2 
  93.          AutoSize        =   -1  'True
  94.          Caption         =   "D3D &device:"
  95.          Height          =   195
  96.          Left            =   360
  97.          TabIndex        =   5
  98.          Top             =   660
  99.          Width           =   900
  100.       End
  101.       Begin VB.Label Label1 
  102.          AutoSize        =   -1  'True
  103.          Caption         =   "&Adapter:"
  104.          Height          =   195
  105.          Left            =   360
  106.          TabIndex        =   1
  107.          Top             =   300
  108.          Width           =   600
  109.       End
  110.    End
  111. End
  112. Attribute VB_Name = "frmSelectDevice"
  113. Attribute VB_GlobalNameSpace = False
  114. Attribute VB_Creatable = False
  115. Attribute VB_PredeclaredId = True
  116. Attribute VB_Exposed = False
  117. Option Explicit
  118.  
  119.  
  120. Dim m_callback As Object
  121.  
  122. Public Sub SelectDevice(callback As Object)
  123.     
  124.     If callback Is Nothing Then Exit Sub
  125.     Set m_callback = callback
  126.     
  127.     Dim dm As D3DDISPLAYMODE
  128.     
  129.     If g_d3dpp.Windowed = 0 Then
  130.  
  131.         m_callback.InvalidateDeviceObjects
  132.     
  133.         D3DUtil_ResetWindowed
  134.  
  135.         m_callback.RestoreDeviceObjects
  136.         
  137.     End If
  138.     
  139.     Me.Show 1
  140.     
  141.     Set m_callback = Nothing
  142.     
  143. End Sub
  144.  
  145.  
  146. Private Sub cboAdapter_Click()
  147.     
  148.     Dim devtype As CONST_D3DDEVTYPE
  149.       
  150.     If (cboDevice.ListIndex = 1) Then
  151.         devtype = D3DDEVTYPE_REF
  152.     Else
  153.         devtype = D3DDEVTYPE_HAL
  154.     End If
  155.        
  156.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  157.     
  158. End Sub
  159.  
  160. Private Sub cboDevice_Change()
  161.     
  162.     Dim devtype As CONST_D3DDEVTYPE
  163.     
  164.     If (cboDevice.ListIndex = 1) Then
  165.         devtype = D3DDEVTYPE_REF
  166.     Else
  167.         devtype = D3DDEVTYPE_HAL
  168.     End If
  169.        
  170.     Call UpdateModes(cboAdapter.ListIndex, devtype)
  171.     
  172. End Sub
  173.  
  174. Private Sub cmdCancel_Click()
  175.  
  176.     Set m_callback = Nothing
  177.     Unload Me
  178.     
  179. End Sub
  180.  
  181. Private Sub cmdOk_Click()
  182.  
  183.     On Local Error Resume Next
  184.     
  185.     Dim bAdapterChanged As Boolean
  186.     Dim bRasterizerChanged As Boolean
  187.     Dim bRef As Boolean
  188.     Dim lWindowed As Long
  189.     Dim AdapterID As Long
  190.     Dim ModeID As Long
  191.     Dim devtype As CONST_D3DDEVTYPE
  192.     
  193.     AdapterID = cboAdapter.ListIndex
  194.     ModeID = cboFullScreenMode.ListIndex
  195.         
  196.     ' see if user changed adapters
  197.     If g_lCurrentAdapter <> AdapterID Then bAdapterChanged = True
  198.                 
  199.     bRef = g_Adapters(g_lCurrentAdapter).bReference
  200.         
  201.     If (cboDevice.ListIndex = 1) Then
  202.         devtype = D3DDEVTYPE_REF
  203.     Else
  204.         devtype = D3DDEVTYPE_HAL
  205.     End If
  206.     
  207.     ' see if user changed rasterizers
  208.     If (devtype = D3DDEVTYPE_REF And bRef = False) Then bRasterizerChanged = True
  209.     If (devtype = D3DDEVTYPE_HAL And bRef = True) Then bRasterizerChanged = True
  210.     
  211.     
  212.     If optRenderingMode(1).Value = True Then
  213.         lWindowed = 0
  214.     Else
  215.         lWindowed = 1
  216.     End If
  217.         
  218.     ' if they didnt change adapters or switch to refrast, then we can just use reset
  219.     If bAdapterChanged = False And bRasterizerChanged = False Then
  220.                 
  221.         'If trying to go Fullscreen
  222.         If lWindowed = 0 Then
  223.         
  224.             'call g_dev.reset
  225.             Call D3DUtil_ResizeFullscreen(g_focushwnd, cboFullScreenMode.ListIndex)
  226.         
  227.         Else
  228.             
  229.             Call D3DUtil_ResizeWindowed(g_focushwnd)
  230.         
  231.         End If
  232.         
  233.         'tell user needs to restore device objects
  234.         m_callback.RestoreDeviceObjects
  235.         
  236.         'exit modal dialog
  237.         Unload Me
  238.         Exit Sub
  239.  
  240.     End If
  241.     
  242.     Set g_dev = Nothing
  243.     
  244.     D3DUtil_ReleaseAllTexturesFromPool
  245.     
  246.     'tell user to lose reference counts in its objects device objects
  247.     m_callback.InvalidateDeviceObjects
  248.     m_callback.DeleteDeviceObjects
  249.     
  250.     'Reinitialize D3D
  251.     If lWindowed = 0 Then
  252.         D3DUtil_InitFullscreen g_focushwnd, AdapterID, ModeID, devtype, True
  253.     Else
  254.         D3DUtil_InitWindowed g_focushwnd, AdapterID, devtype, True
  255.     End If
  256.     If g_dev Is Nothing Then
  257.         'The app still hit an error. Both HAL and REF devices weren't created. The app will have to exit at this point.
  258.         MsgBox "No suitable device was found to initialize D3D. Application will now exit.", vbCritical
  259.         End
  260.         Exit Sub
  261.     End If
  262.     
  263.         
  264.     'tell user to re-create device objects
  265.     m_callback.InitDeviceObjects
  266.     
  267.     'tell user to restore device objects
  268.     m_callback.RestoreDeviceObjects
  269.     
  270.     'exit modal dialog
  271.     Unload Me
  272.  
  273. End Sub
  274.  
  275. Private Sub Form_Load()
  276.         
  277.     Call UpdateAdapters
  278.     Call UpdateDevices(g_lCurrentAdapter)
  279.     Call UpdateModes(g_lCurrentAdapter, g_Adapters(g_lCurrentAdapter).DeviceType)
  280.     
  281. End Sub
  282.  
  283. Private Sub UpdateAdapters()
  284.  
  285.     Dim i As Long, j As Long
  286.     Dim sDescription As String
  287.     
  288.     cboAdapter.Clear
  289.         
  290.     For i = 0 To g_lNumAdapters - 1
  291.         
  292.         sDescription = vbNullString
  293. '        For j = 0 To 511
  294. '            sDescription = sDescription & Chr$(g_Adapters(i).d3dai.Description(j))
  295. '        Next
  296. '        sDescription = Replace$(sDescription, Chr$(0), " ")
  297.         sDescription = StrConv(g_Adapters(i).d3dai.Description, vbUnicode)
  298.         cboAdapter.AddItem sDescription
  299.     Next
  300.     
  301.     cboAdapter.ListIndex = g_lCurrentAdapter
  302.     
  303. End Sub
  304.  
  305. Private Sub UpdateDevices(adapter As Long)
  306.  
  307.     Dim i As Long
  308.     
  309.     cboDevice.Clear
  310.     
  311.     cboDevice.AddItem "HAL"
  312.     cboDevice.AddItem "REF"
  313.     
  314.     'If g_Adapters(g_lCurrentAdapter).bReference Then
  315.     If g_Adapters(adapter).bReference Then
  316.         cboDevice.ListIndex = 1
  317.     Else
  318.         cboDevice.ListIndex = 0
  319.     End If
  320.     
  321. End Sub
  322.  
  323. Private Sub UpdateModes(adapter As Long, devtype As CONST_D3DDEVTYPE)
  324.  
  325.     Dim i As Long
  326.     Dim pAdapter As D3DUTIL_ADAPTERINFO
  327.     Dim sModeString As String
  328.     
  329.     cboFullScreenMode.Clear
  330.             
  331.     With g_Adapters(adapter).DevTypeInfo(devtype)
  332.         For i = 0 To .lNumModes - 1
  333.             sModeString = .Modes(i).lWidth & " x "
  334.             sModeString = sModeString & .Modes(i).lHeight & " x "
  335.             If .Modes(i).format = D3DFMT_X8R8G8B8 Or _
  336.                 .Modes(i).format = D3DFMT_A8R8G8B8 Or _
  337.                 .Modes(i).format = D3DFMT_R8G8B8 Then
  338.                 sModeString = sModeString & "32"
  339.             Else
  340.                 sModeString = sModeString & "16"
  341.             End If
  342.             
  343.             cboFullScreenMode.AddItem sModeString
  344.         Next
  345.         If cboFullScreenMode.ListCount > 0 Then cboFullScreenMode.ListIndex = .lCurrentMode
  346.     End With
  347.                 
  348. End Sub
  349.  
  350. Private Sub optRenderingMode_Click(Index As Integer)
  351.     
  352.     If Index = 1 Then
  353.         cboFullScreenMode.Enabled = True
  354.     Else
  355.         cboFullScreenMode.Enabled = False
  356.     End If
  357.     
  358. End Sub
  359.